home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / VideoToolbox 96.06.15 / VideoToolboxSources / CenterRectInRect.c < prev    next >
Text File  |  1995-06-18  |  2KB  |  79 lines

  1. /*
  2. CenterRectInRect.c
  3. ©1991-1995 Denis G. Pelli
  4. These routines are trivial, but enhance the readability of programs that use them.
  5.  
  6. HISTORY:
  7. 8/24/91    dgp    Made compatible with THINK C 5.0.
  8. 1/25/93 dgp removed obsolete support for THINK C 4.
  9. 11/22/94 dgp renamed "RectInRect" to IsRectInRect().
  10. 5/31/95 dgp added ExpandRect, ExpandAndOffsetRect, and ShrinkRect.
  11. 6/17/95 dgp rewrote ShrinkRect to extend the rect to fully include any partial tiles.
  12. */
  13. #include "VideoToolbox.h"
  14.  
  15. void CenterRectInRect(Rect *a,Rect *b)
  16. {
  17.     OffsetRect(a,(b->left + b->right - a->left - a->right)/2
  18.         ,(b->top + b->bottom - a->top - a->bottom)/2);
  19. }
  20.  
  21. void OffsetRectTile(Rect *r,int nx,int ny)
  22. // Shift rect by multiples of itself
  23. {
  24.     OffsetRect(r,nx*(r->right-r->left),ny*(r->bottom-r->top));
  25. }
  26.  
  27. Boolean IsRectInRect(Rect *r,Rect *R)
  28. // Is the first rect entirely inside the second?
  29. // If either rect has zero area then this routine will return false.
  30. {
  31.     Rect t;
  32.     
  33.     if(!SectRect(r,R,&t))return 0;
  34.     return EqualRect(r,&t);
  35. }
  36.  
  37. void ShrinkRect(Rect *r,int hDivisor,int vDivisor)
  38. // Imagine that the plane is tiled by rects of size hDivisor by vDivisor.
  39. // We first extend your rect to fully include any tiles that were only partly included.
  40. // Then we shrink your rect by hDivisor and vDivisor.
  41. {
  42.     r->top=floor((float)r->top/vDivisor);
  43.     r->bottom=ceil((float)r->bottom/vDivisor);
  44.     r->left=floor((float)r->left/hDivisor);
  45.     r->right=ceil((float)r->right/hDivisor);
  46. }
  47.  
  48. void ExpandRect(Rect *r,double hMag,double vMag)
  49. {
  50.     r->top=round(r->top*vMag);
  51.     r->bottom=round(r->bottom*vMag);
  52.     r->left=round(r->left*hMag);
  53.     r->right=round(r->right*hMag);
  54. }
  55.  
  56. void ExpandAndOffsetRect(Rect *r,double hMag,double vMag,double hOffset,double vOffset)
  57. {
  58.     r->top=round(r->top*vMag+vOffset);
  59.     r->bottom=round(r->bottom*vMag+vOffset);
  60.     r->left=round(r->left*hMag+hOffset);
  61.     r->right=round(r->right*hMag+hOffset);
  62. }
  63.  
  64. void LocalToGlobalRect(Rect *r)
  65. {
  66.     Point pt={0,0};
  67.     
  68.     LocalToGlobal(&pt);
  69.     OffsetRect(r,pt.h,pt.v);
  70. }
  71.  
  72. void GlobalToLocalRect(Rect *r)
  73. {
  74.     Point pt={0,0};
  75.     
  76.     GlobalToLocal(&pt);
  77.     OffsetRect(r,pt.h,pt.v);
  78. }
  79.